package com.example.designpatterns.state;

/**
 * 环境类角色（Context）
 */
public class Context {
    public static final IState STATE_A = new ConcreteStateA();
    public static final IState STATE_B = new ConcreteStateB();
    // 默认状态
    private IState currentState = STATE_A;

    public void setState(IState state) {
        this.currentState = state;
        this.currentState.setContext(this);
    }

    public IState getState() {
        return this.currentState;
    }

    public void handle() {
        this.currentState.handle();
    }
}


